﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using blackhouse.BlackApart.Business;
using blackhouse.BlackApart.Business.Apartments;
using blackhouse.BlackApart.Web;
using blackhouse.JavaScript.JQuery;

namespace blackhouse.Aparts.Web.Handlers {

    [Serializable]
    public class ApartmentInfo {

        #region Properties

        public int ApartmentId { get; set; }
        public string ShortName { get; set; }
        public string LongName { get; set; }
        public string Url { get; set; }
        public string ImageUrlPattern { get; set; }
        
        #endregion

        #region Constructors

        public ApartmentInfo() { }

        public ApartmentInfo(IApartmentGroup group) {
            this.ApartmentId = group.Id;
            this.ShortName = group.ShortName;
            this.LongName = group.Name;
            this.Url = UrlUtils.GetApartmentTypeUrl(group, DisplayApartmentTypeView.Default, 1);
            this.ImageUrlPattern = UrlUtils.ApartmentPhotoPrototypeImageUrl(group.MainPhoto.PhotoName);
        }

        #endregion

        #region Methods

        public static ApartmentInfo[] GetAll() {
            return Factory.Instance().GetApartmentGroup().GetAllApartmentTypes().OrderBy(a => a.ShortName).Select(g => new ApartmentInfo(g)).ToArray();
        }

        /// <summary>
        /// Dodaje funkcję javascript GetAllApartments, która jako parametr otrzymuje delegację funkcji przyjmującą za argument listę apartamentów
        /// </summary>
        public static void AdJs() {
            JQueryLibraries jql = new JQueryLibraries();
            jql.IncludeFileBasedOnJQuery("blackhouse.Aparts.Web.Scripts.apartment-info.js,blackhouse.Aparts.Web");
        }

        #endregion

    }
}